package com.ly.hotel.util;


import android.text.TextUtils;
import android.util.Log;

import com.ly.hotel.common.MyApplication;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.io.ByteArrayInputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class InterfaceConfUtil {
	//插件配置

	public static String getConf(String type,String tagName,String defaultBack){
		String backString = defaultBack;
		if(!TextUtils.isEmpty(MyApplication.pluginCfg) && !TextUtils.isEmpty(MyApplication.interfaceVersion)){
			try {
				DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
				DocumentBuilder dombuilder = domfac.newDocumentBuilder();
				Document doc = dombuilder.parse(new ByteArrayInputStream(MyApplication.pluginCfg.getBytes("utf-8")));
				NodeList obj = doc.getElementsByTagName(MyApplication.interfaceVersion);

				NodeList sysList = ((Element) obj.item(0)).getElementsByTagName(type);
				if (sysList.getLength() > 0) {
					NodeList headList = ((Element) sysList.item(0)).getElementsByTagName(tagName);
					if (headList.getLength() > 0 && headList.item(0) != null && headList.item(0).hasChildNodes()) {
						backString = headList.item(0).getFirstChild().getNodeValue();
					}
				}

			}catch (Exception e){
				Log.e("InterfaceConfUtil","解析" + tagName + "出错" + ":" + type + ":" + tagName);
			}
		}
		return backString;
	}
}
